<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/head::head('','/css/bootstrap/select/bootstrap-select.min.css','/js/laydate/laydate.js,/js/jquery-validate/jquery.validate.min.js,/js/bootstrap/select/bootstrap-select.min.js,/js/bootstrap/select/defaults-zh_CN.min.js')">
</head>
<script th:inline="javascript">
    /*<![CDATA[*/

    var basePath = /*[[${#httpServletRequest.getScheme() + "://" + #httpServletRequest.getServerName() + ":" + #httpServletRequest.getServerPort() + #httpServletRequest.getContextPath()}]]*/ 'basepath';


    function addOrg(){
        var valiReuslt = $("#addForm").valid();
        if(!valiReuslt){
            return false;
        }
        var formData = $("#addForm").serialize();
        var url = basePath + "/lims/orgnazation/orgAdd";
        $.post({
            url:url,
            data:formData,
            dataType:"json",
            success:function(data){
                if(data){
                    parent.spop({
                        template: '添加成功',
                        position  : 'top-center',
                        style: 'success',
                        autoclose: 2000
                    });
                    closeModal();
                    parent.openMainFrame("/lims/orgnazation/orgList");
                }else{
                    parent.spop({
                        template: '添加失败',
                        position  : 'top-center',
                        style: 'error',
                        autoclose: 3000
                    });
                }
            }
        });


    }

    function closeModal(){
        parent.closeModal();

    }

    $(function(){
        $("#addForm").validate({
            rules:{
                orgName:"required",
                orgCode:"required"
            },
            messages:{
                orgName:"请输入组织名称",
                orgCode:"请输入组织编码"
            }
        });

    });



    /*]]>*/
</script>



<body>
    <div class="container">

        <form th:id="addForm" class="form-control" style="width: 108%;margin-left: -15px;">
            <div th:id="messageDiv" class="alert alert-danger alert-dismissable" style="width: 400px;
            margin-bottom: 15px;display: none">
                <button type="button" class="close" data-dismiss="alert"></button>
                <strong th:id="messageDiv"></strong>
            </div>
            <div class="input-group mb-3">
              <div class="input-group-prepend">
                <span class="input-group-text glyphicon glyphicon-star" style="color: #ff0000;">组织名称</span>
              </div>
              <input type="text" th:id="orgName" th:name="orgName" class="form-control" autocomplete="off" >

            </div>
            <div class="input-group mb-3">
                <div class="input-group-prepend">
                    <span class="input-group-text glyphicon glyphicon-star" style="color: #ff0000;">组织编码</span>
                </div>
                <input type="text" th:id="orgCode" th:name="orgCode" autocomplete="off" class="form-control">
            </div>
            <div class="input-group mb-3">
                <div class="input-group-prepend">
                    <span class="input-group-text glyphicon glyphicon-star" style="color: #ff0000;">父级组织</span>
                </div>
                <select th:name="parentId" th:id="parentId" class="form-control">
                    <option th:value="0">无</option>
                    <option th:each="orgnazation:${orgnazationList}" th:value="${orgnazation.orgId}" th:text="${orgnazation.orgName}" ></option>
                </select>
            </div>
            <div class="input-group mb-3">
                <div class="input-group-prepend">
                    <span class="input-group-text">是否启用</span>
                </div>
                <div class="RadioStyle">
                    <div class="Block PaddingL">
                        <input type="radio" name="available" id="available1" th:value="1" th:checked="checked"/>
                        <label for="available1">启用</label>
                        <input type="radio" name="available"  id="available2" value="0"/>
                        <label for="available2">不启用</label>
                    </div>
                </div>
            </div>
            <div th:align="right">
                <button type="button" th:onclick="'javascript:addOrg()'" th:name="addUserBtn"  class="btn btn-primary">添加</button>
                <button type="reset" class="btn btn-warning">重置</button>
                <button type="button" th:onclick="'javascript:closeModal()'" class="btn btn-secondary">关闭</button>
            </div>

        </form>
    </div>

</body>



</html>